<template>
    <div class="login_page">
        <div class="logo_box">
            <h3>后台管理页面</h3>
            <form action="#" name="f" method="post">
                <div class="input_outer">
                    <span class="u_user"></span>
                    <input name="logname" autocomplete="off" class="text" placeholder="请输入用户名" v-model="formline.username" type="text">
                </div>
                <div class="input_outer">
                    <span class="u_user"></span>
                    <input name="logname" @keyup.enter="loginFunc" autocomplete="off" class="text" placeholder="请输入密码" v-model="formline.pawword" value="输入密码登陆" style="color: #FFFFFF !important" type="password">
                </div>
                <div class="mb2">
                    <a class="act-but submit" @click="loginFunc()" href="javascript:;" style="color: #FFFFFF">登录</a>
                </div>
                <!-- <input name="savesid" value="0" id="check-box" class="checkbox" type="checkbox"><span>记住用户名</span> -->
            </form>
            <a href="#" class="login-fgetpwd" style="color: #FFFFFF">忘记密码？</a>
        </div>
    </div>
</template>
<script>
import g from '../../components/global.js'
export default {
  data() {
    return {
      formline: {
        username: '',
        pawword: ''
      }
    }
  },
  methods:{
      loginFunc(){
          var _this = this
          $.ajax({
              type:'POST',
              url:g.res_url+'/api/v1/admin_login',
              data:{
                  username:_this.formline.username,
                  password:_this.formline.pawword
              },
              success:function(data){
                  var dataObj = JSON.parse(data)

                  if(dataObj.code == 200){
                       sessionStorage.setItem("username", dataObj.data.username)
                       sessionStorage.setItem("token", dataObj.data.token)
                      _this.$message.success('登录成功')
                      _this.$router.push('/admin')
                  }else{
                      _this.$message.error(dataObj.msg)
                  }
              },
              error:function(){
                  _this.$message.error('网络繁忙，请稍后重试！')
              }
          })
      }
  }
}
</script>

<style>
@import url("../../../static/css/login.css");
.bg_black {
  width: 100%;
  height: 100%;
  background: #000;
}
</style>

